home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / AppKiller / ak_ppc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-16  |  2.4 KB  |  104 lines  |  [TEXT/ALFA]

  1. /*********
  2. ** ak_ppc.c
  3. **
  4. ** contains code for ppc functions of the program
  5. ** and code for launching other apps.
  6. ***********/
  7.  
  8. #ifndef THINK_C
  9.  /* include the <standard mac headers> */
  10. #include <AppleEvents.h>
  11. #include <Desk.h>
  12. #include <Dialogs.h>
  13. #include <Events.h>
  14. #include <Fonts.h>
  15. #include <GestaltEqu.h>
  16. #include <Menus.h>
  17. #include <OSEvents.h>
  18. #include <QuickDraw.h>
  19. #include <THINK.h>
  20. #include <ToolUtils.h>
  21. #include <Types.h>
  22. #include <Windows.h>
  23. #else
  24.  #include "ak_headers"
  25. #endif
  26. #include <StandardFile.h>
  27. #include <string.h>
  28. #include "ak_ppc.h"
  29.  
  30. void DoAlert(Str255, Str255, Str255, Str255); /* in appkiller.c */
  31.  
  32. void MyPPCInit(void)
  33. {
  34.     OSErr err;
  35.     err = PPCInit();
  36. } /* MyPPCInit() */
  37.  
  38.  
  39. void PostWithPPCBrowser(void)        /* p. 5-25, Inside Macintosh-6 */
  40. {
  41.     EventRecord    myHLEvent;
  42.     OSErr    myErr;
  43.     PortInfoRec    myPortInfo;
  44.     TargetID    myTarget;
  45.     
  46.     myErr = PPCBrowser("\pSelect an Application to Stop", "\pApplication", FALSE,
  47.         &myTarget.location, &myPortInfo, NULL, "\p");
  48.     if (myErr == noErr) {
  49.  
  50.         /* copy portname into myTarget.name */
  51.  
  52.         BlockMove( &myPortInfo.name, &myTarget.name, 
  53.                 sizeof(myPortInfo.name));
  54.         myHLEvent.what = kHighLevelEvent;
  55.         myHLEvent.message = (long)kCoreEventClass;
  56.         *(long*)(&myHLEvent.where) = (long)kAEQuitApplication;
  57.         
  58.         myErr = PostHighLevelEvent(&myHLEvent, (long)&myTarget, 0, NULL,0,
  59.                         receiverIDisTargetID);
  60.         } /* if */
  61. } /* PostWithPPCBrowser() */
  62.  
  63.  
  64. void DoLaunch(void)
  65. {
  66.     // PLAN OF ATTACK:
  67.     //
  68.     // 1) pop up standard file open box; select any file of type APPL
  69.     // 2) SubLaunch the application, while keeping ourselves alive.
  70.     // 3) Cleanup(?) and return.
  71.  
  72.     StandardFileReply theSFR;
  73.     SFTypeList    theTypes;
  74.     OSErr    err;
  75.  
  76.     theTypes[0] = 'APPL';    /* to launch any application */
  77.     theTypes[1] = 'FNDR';    /* to launch the finder again */
  78.     
  79.     StandardGetFile(NULL, 2, theTypes, &theSFR);        // 1)
  80.     
  81.     if ( theSFR.sfGood == TRUE) { 
  82.         LaunchParamBlockRec    launchParams;
  83.         
  84.         launchParams.launchBlockID = extendedBlock;
  85.         launchParams.launchEPBLength = extendedBlockLen;
  86.         launchParams.launchFileFlags = 0;
  87.         launchParams.launchControlFlags = launchContinue +
  88.                                           launchNoFileFlags;
  89.         launchParams.launchAppSpec = &(theSFR.sfFile);
  90.         launchParams.launchAppParameters = NULL;
  91.         
  92.         err = LaunchApplication(&launchParams);            // 2)
  93.         
  94.         if (err != noErr) DoAlert("\pSorry, an error occured and",
  95.             "\pSystem 7 choked.", "\p", "\p");
  96.     } /* if user selected file... */
  97.     
  98.     return;                                                // 3)
  99. } /* DoLaunch() */
  100.  
  101.  
  102.  
  103.  
  104.